import  time
import datetime
from datetime import  timedelta


def my_datetime_exercise():
    now = datetime.datetime.now(tz=None)
    my_timestamp = now.timestamp()  # 时间戳
    print(my_timestamp)
    my_timestamp_to_datetime = datetime.datetime.fromtimestamp(my_timestamp, tz=None)
    print(type(my_timestamp_to_datetime))
    my_datetime_to_str = now.strftime("%Y-%m-%d %H:%M:%S")  # 转换成字符串
    print(my_datetime_to_str)
    my_str_to_datetime = datetime.datetime.strptime(my_datetime_to_str, "%Y-%m-%d %H:%M:%S")
    print(type(my_str_to_datetime))  # 转换成Datetime 格式


# 封装一个函数`get_date(day_delta)`, 如果传入的是`-1` , 输出就是**字符串**日期
def get_date(day_delta):
    now_time = datetime.datetime.now(tz=None)
    my_result = now_time+timedelta(days=day_delta)
    my_today_date = my_result.strftime("%Y-%m-%d")
    print(my_today_date)
